package com.zxp.cloud.order.controller;

import com.zxp.cloud.order.model.Order;
import com.zxp.cloud.order.service.OrderService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @author shollin
 * @desc
 * @date 2021/7/18/018 9:40
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@RefreshScope
public class OrderController {

    @Value("${author:}")
    public String author;

    private final RestTemplate restTemplate;

    private final OrderService orderService;

    @GetMapping("/")
    public String index(){
        return "order hello:"+author;
    }

    @RequestMapping("/createOrder")
    public Order createOrder(Long userId, Long productId, Integer count){
        return orderService.createOrder(userId,productId,count);

    }

    @PostMapping("/save")
    public Order save(@RequestBody Order order){
        return orderService.save(order);

    }
}
